﻿using ReflectionStudio.Core.Events;
using System;
using System.Collections.Generic;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using WPFExcelReport.Helpers;
using System.ComponentModel;

namespace WPFExcelReport
{
    /// <summary>
    /// 专用于布卷剪布
    /// </summary>
    public partial class UIQIFWB08 : UIWBBST
    {
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            if (dwMaster == null)
            {
                RWAUF = "";
                ABAUF = "";
                QTY = 0;
            }
            else
            {
                RWAUF = TMV.WBBRWKRS + TMV.WBBRWLFD + TMV.WBBPOS;
                QTY = TMV.WBBSSTKLG;
                CPCS = int.Parse(TMV.WBBZMT.ToString());
                SHIFT = TMV.WBBREFSCHL;
            }
        }
        public Dictionary<string, object> QPM = new Dictionary<string, object>();
        public override void OnTTPONSTsChg(double points)
        {
            QPM["TTPOINTS"] = points;
            QPM["MTR"] = CMTR;
            bgWorker.RunWorkerAsync();
            //QUALITY =TMV.QLTAUTO(PM);
            base.OnTTPONSTsChg(points);
        }
        public override void bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            //if (!TMV.IsBusy)
                TMV.QLTAUTO(QPM);
            //TMV.IsBusy = true;
            //base.bgWorker_DoWork(sender, e);
        }
        public override void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            QUALITY = TMV.QUALITY;
            base.bgWorker_RunWorkerCompleted(sender, e);
        }
        public override void LOADBYAUF()
        {
            QTY = 0;
            QUALITY = "1A";
            TBMain.Clear();
            if (ORDERNUM.Length < 12)
                return;
            dwData = TBMain.NewRow();
            dwData["WBBMANDANT"] = app.Mandant;
            dwData["WBBSTKNR"] = ORDERNUM;
            SResult = TMV.QWB13(dwData);
            MergeData(SResult, true);
            base.LOADBYAUF();
        }
        public void QulityCommand(object sender, RoutedEventArgs e)
        {
            QPM["TTPOINTS"] = TTPOINTS;
            QPM["MTR"] = CMTR;
            bgWorker.RunWorkerAsync(); 
        } 
        public override void OnCMTRChg(double cmtr)
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            if (dwWS == null)
                return;
            TMV.WBBISTKLG = cmtr;
            EventDispatcher.Instance.RaiseStatus(cmtr + "m", StatusEventType.StopProgress);
            //QTY = CMTR;
            switch (TMV.WBBWAKZ)
            {
                case "R":
                    TMV.WBBSGEW = cmtr * double.Parse(dwWS["WARGRLFD"].ToString()) * 0.001;
                    break;
                case "F":
                    TMV.WBBSGEW = cmtr * double.Parse(dwWS["WAFGRLFD"].ToString()) * 0.001;
                    break;
            }
            /*
            QPM["TTPOINTS"] = TTPOINTS;
            QPM["MTR"] = cmtr;
            bgWorker.RunWorkerAsync();*/
            base.OnCMTRChg(cmtr);
        }
        public override void QIHelper()
        {
            PM["RWKRS"] = TMV.WBBRWKRS;
            PM["RWLFD"] = TMV.WBBRWLFD;
            PM["RWPOS"] = TMV.WBBPOS;
            TMV.RVDEFAULT(PM);//删除现在小布卷的默认疵点
            dwMaster["WBBZMT"] = CPCS;
            TMV.WBBSSTKLG = QTY;
            TMV.WBBREFSCHL = SHIFT;
            TMV.WBBDRKZ1 = "J";
            TMV.InsertWBBST(dwMaster);
            TMV.UpdateWBBST(dwMaster, 0);
            dwData = TMV.VWBW.TBMain.NewRow();
            dwData["WBEWMANDANT"] = app.Mandant;
            dwData["WBEWSTKNR"] = dwMaster["WBBSTKNR"];
            dwData["WBEWMTR"] = dwMaster["WBBSSTKLG"];
            dwData["WBEWGEW"] = dwMaster["WBBSGEW"];
            dwData["WBEWBRT"] = double.Parse(dwMaster["WBBSBRT"].ToString()) * 0.01;
            dwData["WBEWZENSUR"] = dwMaster["WBBZENSUR"];
            dwData["WBEWZENSURKZ"] = dwMaster["WBBZENSURKZ"];
            dwData["WBEWFSCHL"] = dwMaster["WBBREFSCHL"];
            dwData["WBEWMNRKRS"] = dwMaster["WBBWMNRKRS"];
            dwData["WBEWMLFDNR"] = dwMaster["WBBWMLFDNR"];
            dwData["WBEWMPOS"] = dwMaster["WBBWMPOS"];
            dwData["WBEWBS"] = "AND WBEWBS='13'";

            TMV.VWBW.UWBEWMTR(dwData);
            dwData["WBEWMANDANT"] = app.Mandant;
            dwData["WBEWSTKNR"] = dwMaster["WBBSTKNRK"];
            dwData["WBEWBS"] = "AND WBEWTSTKNR='" + dwMaster["WBBSTKNR"].ToString() + "' AND WBEWBS='36'";
            TMV.VWBW.UWBEWMTR(dwData);

            //WBBSTKNRK  WBEWTSTKNR

            PM["RWKRS"] = TMV.WBBRWKRS;
            PM["RWLFD"] = TMV.WBBRWLFD;
            PM["RWPOS"] = TMV.WBBPOS;
            PM["VERSION"] = 1;
            PM["ROLLLG"] = TMV.WBBSSTKLG;
            TMV.VWBF.SETSHIFT(PM);
            base.QIHelper();
        }
        public void ChgQtyCommand(object sender, RoutedEventArgs e)
        {

            TMV.WBBSSTKLG = QTY;
            TMV.UWBSSTKLG(dwMaster);
            dwData = TMV.VWBW.TBMain.NewRow();
            dwData["WBEWMANDANT"] = app.Mandant;
            dwData["WBEWSTKNR"] = dwMaster["WBBSTKNR"];
            dwData["WBEWMTR"] = dwMaster["WBBSSTKLG"];
            dwData["WBEWGEW"] = dwMaster["WBBSGEW"];
            dwData["WBEWBRT"] = double.Parse(dwMaster["WBBSBRT"].ToString()) * 0.01;
            dwData["WBEWZENSUR"] = dwMaster["WBBZENSUR"];
            dwData["WBEWZENSURKZ"] = dwMaster["WBBZENSURKZ"];
            dwData["WBEWFSCHL"] = dwMaster["WBBREFSCHL"];
            dwData["WBEWMNRKRS"] = dwMaster["WBBWMNRKRS"];
            dwData["WBEWMLFDNR"] = dwMaster["WBBWMLFDNR"];
            dwData["WBEWMPOS"] = dwMaster["WBBWMPOS"];
            TMV.VWBW.UWBEWMTR(dwData);
        }

    }
}
